//
//  ReportCardScreenView.m
//  jzyParents
//
//  Created by 任辰东 on 2022/8/22.
//

#import "ReportCardScreenView.h"
#import "UIButton+BackgroundColor.h"

@interface ReportCardScreenView ()

@property (nonatomic, strong) UIButton *classBtn;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIButton *gradeBtn;
@property (nonatomic, strong) UIView *line1;
@property (nonatomic, strong) UIButton *markBtn;
@end

@implementation ReportCardScreenView

-(void)configViewWithModel:(id)model
{
    
}

-(void)classBtnAction
{
    if (!self.classBtn.selected) {
        
        self.classBtn.selected = YES;
        self.gradeBtn.selected = NO;
        self.markBtn.selected = NO;
        
        if (self.screenBlock) {
            self.screenBlock(1);
        }
    }

}

-(void)gradeBtnAction
{
    if (!self.gradeBtn.selected) {
        
        self.classBtn.selected = NO;
        self.gradeBtn.selected = YES;
        self.markBtn.selected = NO;
        
        if (self.screenBlock) {
            self.screenBlock(2);
        }
    }

}

-(void)markBtnAction
{
    if (!self.markBtn.selected) {
        
        self.classBtn.selected = NO;
        self.gradeBtn.selected = NO;
        self.markBtn.selected = YES;
        
        if (self.screenBlock) {
            self.screenBlock(3);
        }
    }
}

-(void)setupViews
{
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;
    self.layer.borderColor = UIColorFromHex(kColorMain).CGColor;
    self.layer.borderWidth = kOnePixel;
    [self addSubview:self.classBtn];
    [self addSubview:self.line];
    [self addSubview:self.gradeBtn];
    [self addSubview:self.line1];
    [self addSubview:self.markBtn];
    
    self.classBtn.selected = YES;
    
    [self.classBtn addTarget:self action:@selector(classBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.gradeBtn addTarget:self action:@selector(gradeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.markBtn addTarget:self action:@selector(markBtnAction) forControlEvents:UIControlEventTouchUpInside];
}

-(void)setupLayout
{
    [self.classBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.bottom.equalTo(self);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(40);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.classBtn.mas_right);
        make.width.mas_equalTo(kOnePixel);
    }];
    
    [self.gradeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.line.mas_right);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(40);
    }];
    
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.gradeBtn.mas_right);
        make.width.mas_equalTo(kOnePixel);
    }];
    
    [self.markBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.right.bottom.equalTo(self);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(40);
    }];
    
}

#pragma mark -- lazyload

-(UIView *)line
{
    if (!_line) {
        _line = [UIView new];
        _line.backgroundColor = UIColorFromHex(kColorMain);
    }
    return _line;
}

-(UIView *)line1
{
    if (!_line1) {
        _line1 = [UIView new];
        _line1.backgroundColor = UIColorFromHex(kColorMain);
    }
    return _line1;
}

-(UIButton *)classBtn
{
    if (!_classBtn) {
        _classBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_classBtn setBackgroundColor:UIColorFromHex(kColorWhite) forState:UIControlStateNormal];
        [_classBtn setBackgroundColor:UIColorFromHex(kColorMain) forState:UIControlStateSelected];
        [_classBtn setTitle:@"班级" forState:UIControlStateNormal];
        [_classBtn setTitleColor:UIColorFromHex(kColorMain) forState:UIControlStateNormal];
        [_classBtn setTitleColor:UIColorFromHex(kColorWhite) forState:UIControlStateSelected];
        _classBtn.titleLabel.font = UIFontSize(12);
    }
    return _classBtn;
}

-(UIButton *)gradeBtn
{
    if (!_gradeBtn) {
        _gradeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_gradeBtn setBackgroundColor:UIColorFromHex(kColorWhite) forState:UIControlStateNormal];
        [_gradeBtn setBackgroundColor:UIColorFromHex(kColorMain) forState:UIControlStateSelected];
        [_gradeBtn setTitle:@"校级" forState:UIControlStateNormal];
        [_gradeBtn setTitleColor:UIColorFromHex(kColorMain) forState:UIControlStateNormal];
        [_gradeBtn setTitleColor:UIColorFromHex(kColorWhite) forState:UIControlStateSelected];
        _gradeBtn.titleLabel.font = UIFontSize(12);
    }
    return _gradeBtn;
}

-(UIButton *)markBtn
{
    if (!_markBtn) {
        _markBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_markBtn setBackgroundColor:UIColorFromHex(kColorWhite) forState:UIControlStateNormal];
        [_markBtn setBackgroundColor:UIColorFromHex(kColorMain) forState:UIControlStateSelected];
        [_markBtn setTitle:@"联考" forState:UIControlStateNormal];
        [_markBtn setTitleColor:UIColorFromHex(kColorMain) forState:UIControlStateNormal];
        [_markBtn setTitleColor:UIColorFromHex(kColorWhite) forState:UIControlStateSelected];
        _markBtn.titleLabel.font = UIFontSize(12);
    }
    return _markBtn;
}
@end
